package com.banzhi.shop.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.entity.MyService.MyService_Data;
import com.banzhi.shop.model.CallBack.MyServiceCallBack;
import com.banzhi.shop.model.IMyServiceModel;
import com.banzhi.shop.model.Impl.MyServiceImpl;
import com.banzhi.shop.utils.ASUtils;
import com.banzhi.shop.utils.LoadingDialogUtils;
import com.banzhi.shop.utils.NoTokenUtils;
import com.banzhi.shop.utils.ShareUtils;
import com.banzhi.shop.utils.ToastUtils;
import com.banzhi.shop.utils.Translucent;

import org.json.JSONObject;

/**
 *   我的客服
 */
public class MyServiceActivity extends BaseActivity implements View.OnClickListener, MyServiceCallBack {
    private ImageView ivback;
    private IMyServiceModel myServiceModel;
    private MyService_Data data;
    private TextView tvphone;
    private TextView tvqq;
    private TextView tvwx;
    private TextView fuzhiqq;
    private TextView fuzhiwx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_service);
        Translucent.setTranslucent(this);
        initViews();
        setListeners();
        myServiceModel = new MyServiceImpl();
        LoadingDialogUtils.showProgress(this, "正在加载,请稍后~");
        myServiceModel.getData(this);
    }

    private void initViews() {
        ivback = (ImageView) findViewById(R.id.iv_back);
        tvphone = (TextView) findViewById(R.id.tv_phone);
        tvqq = (TextView) findViewById(R.id.tv_qq);
        tvwx = (TextView) findViewById(R.id.tv_wx);
        fuzhiqq = (TextView) findViewById(R.id.tv_fuzhiqq);
        fuzhiwx = (TextView) findViewById(R.id.tv_fuzhiwx);
    }

    private void setListeners() {
        ivback.setOnClickListener(this);
        fuzhiqq.setOnClickListener(this);
        fuzhiwx.setOnClickListener(this);
        tvphone.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_fuzhiqq:
                ShareUtils.copyLianjie(this, tvqq.getText().toString().trim());
                break;
            case R.id.tv_fuzhiwx:
                ShareUtils.copyLianjie(this, tvwx.getText().toString().trim());
                break;
            case R.id.tv_phone:
                if (ASUtils.isCanUse(tvphone.getText().toString().trim())) {
                    startActivity(ASUtils.callphone(tvphone.getText().toString().trim()));
                }
                break;
        }
    }

    /**
     * 获取客服数据成功
     *
     * @param object
     */
    @Override
    public void ongetDataSuccess(Object object) {
        data = (MyService_Data) object;
        tvphone.setText(data.getPhone());
        //tvqq改为售后微信1
        tvqq.setText(data.getQq());
        //售后微信2
        tvwx.setText(data.getWx());
    }

    /**
     * 获取客服数据失败
     *
     * @param object
     */
    @Override
    public void ongetDataError(Object object) {
        JSONObject jsonObject = (JSONObject) object;
        NoTokenUtils.loginOut(this, jsonObject);
        ToastUtils.makeToastShort(jsonObject.optString("msg"));
    }
}
